{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c24562e6",
   "metadata": {},
   "source": [
    "# 认识四个内置数据结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "693b48fb",
   "metadata": {},
   "source": [
    "#### 列表：有序的可变对象集合【可以随时增加和减少】\n",
    "#### 元组：有序的不可变对象集合\n",
    "#### 字典：无序的键/值对集合【可以增减但是没有顺序】\n",
    "#### 集合：无序的唯一对象集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9045518b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# 列表[]\n",
    "# 使用列表\n",
    "vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "word = \"Milliways\"\n",
    "# 用in来检查一个对象是否在另一个对象里面\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "aafa422a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:word\n",
      "o\n"
     ]
    }
   ],
   "source": [
    "# 课本第61页练习\n",
    "vowels = ['a', 'e', 'i', 'o', 'u']\n",
    "# 用户输入想要查询的单词\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "# 建立一个空列表用来存储对象\n",
    "found = []\n",
    "for i in word:\n",
    "    if i in vowels:\n",
    "        found.append(i)\n",
    "for vowels in found:\n",
    "    print(vowels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e636ff92",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "# 课本第68页练习\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f34bfc81",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(4):\n",
    "    plist.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "5af17761",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "198fcbef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "# 转换plist的数据形式\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "90fffc0e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "# 课本第83页的练习\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "new_phrase = ''.join(plist[1:3])\n",
    "new_phrase = new_phrase + ''.join([plist[5], plist[4], plist[7], plist[6]])\n",
    "\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9462b712",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
